package tuner;
import org.jfugue.*; 

public class Tuner extends Thread
{
	private Player player;
	private int pitch;
	private Pattern p1;
	private String str;
	

	
	public Tuner ()
	{
		super ("Tuner thread");
		player = new Player();
	}
	
	public Tuner (int pitch)
	{
		super ("Tuner thread");
		
		this.pitch = pitch;
		player = new Player();
		start();
	}
	public Tuner (String str)
	{
		super ("Tuner thread");
		this.str=str;
		player=new Player();
		pitch=-1;
		start();
	}
	public void playPitch (int num)
	{
		
		pitch = num;
		p1 = new Pattern ("[" + num + "]w");
		
		
		player.play(p1);
		player.close();
		
	}
		
	public void playTuning (String str) // uses above playTuning
	{
		
		if (str.contains("Standard"))
		{
			Pattern pattern = new Pattern ("[40]w [45]w [50]w [55]w [59]w [64]w");
			player.play (pattern);
		}
		if (str.equals("Tune down 1/2 Step (Eb, Ab, Db, Gb, Bb, Eb)"))
		{
			Pattern p = new Pattern ("[39]w [44]w [49]w [54]w [58]w [63]w");
			player.play (p);
		}
		if (str.equals("Tune down 1 step (D G C F A D)"))
		{
			Pattern p = new Pattern ("[38]w [43]w [48]w [53]w [57]w [62]w");
			player.play (p);
		}
		if (str.equals("Dropped D (D A D G B E)"))
		{
			Pattern p = new Pattern ("[38]w [45]w [50]w [55]w [59] [64]w");
			player.play (p);
		}
		if (str.contains("Dropped C (C G C F A D)"))
		{
			Pattern p = new Pattern ("[36]w [43]w [48]w [53]w [57]w [62]w");
			player.play (p);
		}
		if (str.contains("Open C (C G C G C E)"))
		{
			Pattern p = new Pattern ("[36]w [43]w [48]w [55]w [61]w [64]w");
			player.play(p);
		}
		player.close();
	}

	@Override
	public void run() 
	{
		
		if (pitch !=-1)//playing a specific pitch
			{
				
				playPitch (pitch);
				player.close();
				return;
			}
			else //playing a pattern
			{
				
				playTuning(str);
				player.close();
				return;
			}
		
		
		
	}
	
	public void stopMe()
	{
		player.close();
	    
	}
	  
	  
}
